package uns.fit.gis.fileio;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import javax.microedition.io.file.FileConnection;

public class PhotoData implements IUserData{
	private byte[] photoData;
	private int currentX;
	private int currentY;
	
	public PhotoData() {
		
	}
	
	public PhotoData(byte[] photoData, int x, int y) {
		this.photoData = photoData;
		currentX = x;
		currentY = y;
	}
	
	public byte[] getPhotoData() {
		return photoData;
	}
	public void setPhotoData(byte[] photoData) {
		this.photoData = photoData;
	}
	public int getCurrentX() {
		return currentX;
	}
	public void setCurrentX(int currentX) {
		this.currentX = currentX;
	}
	public int getCurrentY() {
		return currentY;
	}
	public void setCurrentY(int currentY) {
		this.currentY = currentY;
	}
	
	public void save(FileConnection fc) throws IOException{
		DataOutputStream out = fc.openDataOutputStream();
		out.write(photoData);
		out.write(currentX);
		out.write(currentY);
		out.close();
	}
	
	public void load(FileConnection fc) throws IOException{
		DataInputStream in = fc.openDataInputStream();
		int length = (int)fc.fileSize();
		System.out.println(length);
		// length(x) + length(y) = 8
		photoData = new byte[length - 8];
		in.read(photoData, 0, length - 8);
		currentX = in.readInt();
		currentY = in.readInt();
		in.close();
	}
}
